# RVC Controller SW — Sequence Diagrams (Design Level)

| 항목 | 내용 |
|------|------|
| 문서 번호 | RVC-SD-001 |
| 버전 | v1.2 |
| 작성일 | 2026-05-19 |
| 작성자 | OOAD Team |
| 상태 | 초안 (Draft) |

---

## 변경 이력 (Change History)

| 버전 | 날짜 | 변경 내용 | 작성자 |
|------|------|-----------|--------|
| v1.0 | 2026-05-19 | 최초 작성 — Class Diagram 기반 Design-level SD 8개 도출 | OOAD Team |
| v1.1 | 2026-05-19 | UC Actor(Obstacle Sensor, Dust Sensor, RVC System) 추가 및 HW↔SW 경계 명시 | OOAD Team |
| v1.2 | 2026-05-19 | RVC System Actor 제거(시스템 자체 → :RVC participant 또는 내부 self-call), Sensor Actor 명칭 "(HW)" suffix로 통일 | OOAD Team |

---

## 개요

Design-level Sequence Diagram은 시스템 내부 **객체 간 메시지 흐름**을 표현한다.

| 구분 | SSD | Sequence Diagram (Design) |
|------|-----|--------------------------|
| 시스템 표현 | 블랙박스 | 내부 객체 분해 |
| 참여자 | 외부 Actor + 시스템 경계 | Actor + SW 클래스 인스턴스 |
| 목적 | 시스템 오퍼레이션 도출 | 메서드 할당 및 협력 설계 |

**Actor 기준 (UC 정의 기반)**

HW 물리 센서만 외부 Actor로 정의한다. RVC System은 시스템 자체이므로 Actor가 아닌 SW 참여자(:RVC participant)로 표현하며, Controller 내부에서 시작되는 시나리오(SD-03/05/07)는 self-call로 표현한다.

| Actor | 유형 | 트리거 SD |
|-------|------|----------|
| **Obstacle Sensor (HW)** | Supporting (HW 입력) | SD-02, SD-04 |
| **Dust Sensor (HW)** | Supporting (HW 입력) | SD-06 |
| **Sensor (HW)** | Supporting (HW 입력) | SD-08 |

| SD ID | 대응 UC | 시작점 | 주요 SW 참여 객체 |
|-------|---------|--------|-----------------|
| SD-01 | UC-01 | :RVC (내부 participant) | :RVC, :Controller, :MovementUnit, :CleaningUnit, front:ObstacleSensor, dust:DustSensor |
| SD-02 | UC-02 | Obstacle Sensor (HW) | front:ObstacleSensor, :Controller |
| SD-03 | UC-03 | :Controller self-call | :Controller, :MovementUnit, left:ObstacleSensor, right:ObstacleSensor |
| SD-04 | UC-04 | Obstacle Sensor (HW) | left:ObstacleSensor, right:ObstacleSensor, :Controller |
| SD-05 | UC-05 | :Controller self-call | :Controller, :MovementUnit |
| SD-06 | UC-06 | Dust Sensor (HW) | dust:DustSensor, :Controller |
| SD-07 | UC-07 | :Controller self-call | :Controller, :CleaningUnit |
| SD-08 | UC-08 | Sensor (HW) | :Sensor, :Controller, :MovementUnit |

---

## SD-01 : UC-01 Perform Normal Cleaning

> **시작점:** :RVC (SW participant) — 시스템 내부에서 startCleaning() 호출  
> **설명:** RVC 시작 후 정상 청소 루프 — 이벤트 없는 기본 흐름

```mermaid
---
title: "SD-01 | UC-01: Perform Normal Cleaning"
---
sequenceDiagram
    participant RVC as :RVC
    participant CTR as :Controller
    participant MU as :MovementUnit
    participant CU as :CleaningUnit
    participant FS as front:ObstacleSensor
    participant DS as dust:DustSensor

    RVC->>CTR: startCleaning()
    activate CTR

    CTR->>CU: startCleaning()
    activate CU
    deactivate CU

    CTR->>MU: moveForward()
    activate MU
    deactivate MU

    loop pollSensors()
        CTR->>FS: readData()
        FS-->>CTR: false
        CTR->>DS: readData()
        DS-->>CTR: 0.0
        CTR->>MU: moveForward()
    end

    deactivate CTR
```

![SD-01: UC-01 Perform Normal Cleaning](diagrams/sd_01.png)

---

## SD-02 : UC-02 Detect Obstacle (Front)

> **Actor:** Obstacle Sensor (HW) → front:ObstacleSensor (SW)  
> **설명:** 물리 센서가 장애물을 감지하여 SW 클래스가 Controller에 보고

```mermaid
---
title: "SD-02 | UC-02: Detect Obstacle (Front)"
---
sequenceDiagram
    actor OS as Obstacle Sensor (HW)
    participant FS as front:ObstacleSensor
    participant CTR as :Controller

    OS->>FS: detect()
    activate FS
    FS->>CTR: reportObstacle(FRONT)
    activate CTR
    CTR->>CTR: recordObstacleDetection(FRONT)
    CTR-->>FS: ack()
    deactivate CTR
    deactivate FS
```

![SD-02: UC-02 Detect Obstacle (Front)](diagrams/sd_02.png)

---

## SD-03 : UC-03 Avoid Front Obstacle

> **시작점:** :Controller self-call — pollSensors() 중 장애물 감지 시 내부 호출  
> **설명:** 전방 장애물 감지 후 정지 → 좌우 확인 → 회전 → 전진 재개

```mermaid
---
title: "SD-03 | UC-03: Avoid Front Obstacle"
---
sequenceDiagram
    participant CTR as :Controller
    participant MU as :MovementUnit
    participant LS as left:ObstacleSensor
    participant RS as right:ObstacleSensor

    CTR->>CTR: avoidFrontObstacle()
    activate CTR

    CTR->>MU: stop()
    activate MU
    deactivate MU

    CTR->>CTR: checkSideObstacles()
    CTR->>LS: isObstacleDetected()
    LS-->>CTR: boolean
    CTR->>RS: isObstacleDetected()
    RS-->>CTR: boolean

    alt LEFT or RIGHT is free
        CTR->>MU: turn(freeDirection)
        activate MU
        deactivate MU
        CTR->>MU: moveForward()
        activate MU
        deactivate MU
    else Both LEFT and RIGHT blocked
        CTR->>CTR: avoidAllDirectionObstacle()
    end

    deactivate CTR
```

![SD-03: UC-03 Avoid Front Obstacle](diagrams/sd_03.png)

---

## SD-04 : UC-04 Detect Obstacle (Left & Right)

> **Actor:** Obstacle Sensor (HW) → left/right:ObstacleSensor (SW)  
> **설명:** 좌·우 물리 센서가 장애물을 감지하여 SW 클래스가 Controller에 보고

```mermaid
---
title: "SD-04 | UC-04: Detect Obstacle (Left & Right)"
---
sequenceDiagram
    actor OS as Obstacle Sensor (HW)
    participant LS as left:ObstacleSensor
    participant RS as right:ObstacleSensor
    participant CTR as :Controller

    OS->>LS: detect()
    activate LS
    LS->>CTR: reportObstacle(LEFT)
    activate CTR
    CTR->>CTR: recordObstacleDetection(LEFT)
    CTR-->>LS: ack()
    deactivate CTR
    deactivate LS

    OS->>RS: detect()
    activate RS
    RS->>CTR: reportObstacle(RIGHT)
    activate CTR
    CTR->>CTR: recordObstacleDetection(RIGHT)
    CTR-->>RS: ack()
    deactivate CTR
    deactivate RS
```

![SD-04: UC-04 Detect Obstacle (Left & Right)](diagrams/sd_04.png)

---

## SD-05 : UC-05 Avoid All-Direction Obstacle

> **시작점:** :Controller self-call — avoidFrontObstacle() 내 양측 막힘 시 내부 호출  
> **설명:** 전·좌·우 모두 장애물 — 후진 → 회전 → 전진 재개

```mermaid
---
title: "SD-05 | UC-05: Avoid All-Direction Obstacle"
---
sequenceDiagram
    participant CTR as :Controller
    participant MU as :MovementUnit

    CTR->>CTR: avoidAllDirectionObstacle()
    activate CTR

    CTR->>MU: stop()
    activate MU
    deactivate MU

    CTR->>MU: moveBackward()
    activate MU
    deactivate MU

    CTR->>MU: turn(freeDirection)
    activate MU
    deactivate MU

    CTR->>MU: moveForward()
    activate MU
    deactivate MU

    deactivate CTR
```

![SD-05: UC-05 Avoid All-Direction Obstacle](diagrams/sd_05.png)

---

## SD-06 : UC-06 Detect Dust

> **Actor:** Dust Sensor (HW) → dust:DustSensor (SW)  
> **설명:** 물리 먼지 센서가 먼지를 감지하여 SW 클래스가 Controller에 보고

```mermaid
---
title: "SD-06 | UC-06: Detect Dust"
---
sequenceDiagram
    actor DS_HW as Dust Sensor (HW)
    participant DS as dust:DustSensor
    participant CTR as :Controller

    DS_HW->>DS: detect()
    activate DS
    DS->>CTR: reportDust(dustLevel)
    activate CTR
    CTR->>CTR: recordDustDetection(dustLevel)
    CTR-->>DS: ack()
    deactivate CTR
    deactivate DS
```

![SD-06: UC-06 Detect Dust](diagrams/sd_06.png)

---

## SD-07 : UC-07 Boost Cleaning Power

> **시작점:** :Controller self-call — recordDustDetection() 후 내부 호출  
> **설명:** 먼지 감지 후 청소 파워 증가 → boostDuration 경과 후 복귀

```mermaid
---
title: "SD-07 | UC-07: Boost Cleaning Power"
---
sequenceDiagram
    participant CTR as :Controller
    participant CU as :CleaningUnit

    CTR->>CTR: boostCleaningPower()
    activate CTR

    CTR->>CU: boostPower()
    activate CU
    CU-->>CTR: PowerLevel.BOOSTED
    deactivate CU

    CTR->>CU: restoreNormalPower()
    activate CU
    CU-->>CTR: PowerLevel.NORMAL
    deactivate CU

    deactivate CTR
```

![SD-07: UC-07 Boost Cleaning Power](diagrams/sd_07.png)

---

## SD-08 : UC-08 Handle Sensor Error

> **Actor:** Sensor HW → :Sensor (SW)  
> **설명:** 물리 센서 오류 → SW 센서 클래스가 Controller에 보고 → 유효성 검사 → 유지 또는 정지

```mermaid
---
title: "SD-08 | UC-08: Handle Sensor Error"
---
sequenceDiagram
    actor SEN_HW as Sensor (HW)
    participant SEN as :Sensor
    participant CTR as :Controller
    participant MU as :MovementUnit

    SEN_HW->>SEN: detect()
    activate SEN
    SEN->>CTR: reportSensorError(sensorId)
    activate CTR

    CTR->>CTR: validateSensorData(sensorId)

    alt Transient error
        CTR->>CTR: retainLastValidState()
    else Persistent error
        CTR->>MU: stop()
        activate MU
        deactivate MU
    end

    deactivate CTR
    deactivate SEN
```

![SD-08: UC-08 Handle Sensor Error](diagrams/sd_08.png)
